package com.example.demo;

import java.net.URI;

import javax.websocket.ClientEndpoint;
import javax.websocket.ContainerProvider;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;

@ClientEndpoint
public class WebSocketTest3{
	private Session session;
	private Integer k=0;

	public WebSocketTest3() {
	}


	protected boolean start() {
		WebSocketContainer container = ContainerProvider.getWebSocketContainer();
		String uri = "ws://192.168.0.162/websocket?departMent=2&userCode=" + k++;
		//String uri = "ws://192.168.0.162:8081/websocket/websocket?departMent=2&userCode=" + (k++);
		try {
			session = container.connectToServer(WebSocketTest3.class, URI.create(uri));
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public static void main(String[] args) {
		for (int i = 1; i < 50000; i++) {
			WebSocketTest3 wSocketTest = new WebSocketTest3();
			if (!wSocketTest.start()) {
				System.out.println("测试结束！");
				break;
			}
		}
	}
}
